package com.xd.study.fragment;

import android.app.Fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.xd.study.R;

/**
 * Created by DGF on 2015/4/24.
 */
public class StaticFragment extends Fragment {

    //测试静态Fragment的传值
    String content;

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        //return super.onCreateView(inflater, container, savedInstanceState);

        //layout布局文件转换为view

        /**
         * resource: Fragment需要加载的布局文件
         * root: 加载layout的父ViewGroup
         * attactToRoot: false, 不返回ViewGroup
         */
        View view = inflater.inflate(R.layout.fragment, container, false);

        TextView textView = (TextView)view.findViewById(R.id.fragment_textview);
        textView.setText("静态加载Fragment");

        Button button = (Button)view.findViewById(R.id.fragment_static_pass_value);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Toast.makeText(getActivity(), "获取到Activity的传值："+getContent(), Toast.LENGTH_SHORT).show();
            }
        });

        return view;
    }
}
